/**
 *Copyright (c) 2024 watereyes
 * workflow is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.workflow.common.service.impl;

import java.net.URL;

import org.apache.axis.client.Call;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.koron.workflow.common.service.MessageSendService;

@Service
public class MessageSendServiceImpl implements MessageSendService{
	
	private static final Logger LOGGER = LoggerFactory.getLogger(MessageSendServiceImpl.class);
	
	@Value("${mobile.username}")
	private String username;
	@Value("${mobile.password}")
	private String password;
	@Value("${mobile.url}")
	private String url;

	public boolean sendMessage(String mobile, String content)  {
		StringBuilder strBuil = new StringBuilder();
		strBuil.append("<sendbody><message><orgaddr></orgaddr><mobile>");
		strBuil.append(mobile);
		strBuil.append("</mobile><content>");
		strBuil.append(content);
		strBuil.append("</content><sendtime></sendtime><needreport>0</needreport>");
		strBuil.append("</message><publicContent> 【流程平台】</publicContent></sendbody>");
		try {
			org.apache.axis.client.Service service = new org.apache.axis.client.Service();
			Call call = (Call) service.createCall();
			call.setTargetEndpointAddress(new URL(url));
			call.setOperationName("InsertDownSms");
			String responseMessage = (String) call.invoke(new Object[] { username, password, "0", strBuil.toString()});
			LOGGER.info("短信发送返回消息：{}", responseMessage);
			return true;
		} catch (Exception e) {
			LOGGER.error("短信发送失败!", e);
		}
		return false;
	}

}
